package com.liu.dao.impl;

import com.liu.dao.IFavoriteDao;
import com.liu.dto.CollectDTO;
import com.liu.util.LoggerFactory;

import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 老刘Matthew
 * @Timestamp 2022/14 23:31
 * @Description
 */
public class FavoriteDaoImpl extends GenericDaoImpl<CollectDTO> implements IFavoriteDao, LoggerFactory {

    //会员收藏信息查询
    @Override
    public List<CollectDTO> queryFavoriteByUser_id(Integer user_id) throws SQLException {

        String sql = //
                "select " +
                    "author_name, " +
                    "user_name, " +
                    "favorite_time " +
                "from favorite f " +
                "join novel n " +
                "on f.novel_id = n.novel_id " +
                "join user on f.user_id = user.user_id " +
                "where user.user_id = " + user_id;

        return jdbcTemplate.query(sql, resultSet -> {

            List<CollectDTO> list = new ArrayList<>();

            while (resultSet.next()) {

                CollectDTO o = new CollectDTO();
                o.setAuthor_name(resultSet.getString("author_name"));
                o.setUser_name(resultSet.getString("user_name"));
                o.setFavorite_time(resultSet.getTimestamp("favorite_time"));

                list.add(o);
            }

            return list;

        });
    }

    @Override
    public Integer delete(String author_name) throws SQLException {

        String sql = "delete from favorite where author_name = ?";

        return jdbcTemplate.updateOrInsert(sql, //
                new Object[]{
                        author_name,
                },
                new Integer[]{
                        Types.VARCHAR,
                });
    }


    @Override
    public Integer save(CollectDTO collectDTO) throws SQLException {
        return null;
    }

    @Override
    public Integer update(CollectDTO collectDTO) throws SQLException {
        return null;
    }

    @Override
    public List<CollectDTO> query(String where) throws SQLException {
        return null;
    }

    @Override
    public List<CollectDTO> queryAll() throws SQLException {
        return null;
    }

    @Override
    public CollectDTO querySingle(Integer id) throws SQLException {
        return null;
    }

    @Override
    public Integer queryCount(String table, String where) throws SQLException {
        return null;
    }

}
